#/bin/bash

NORMALDIR="normaldir"
QUOTADIR="quotadir"
LOGPATH="/root/log_ior/quota_enable_modify_cache_0308_2"; mkdir -p ${LOGPATH}
MPI_PARAM="--allow-run-as-root -np 8"
IOR_PARAM="-v -a POSIX -g -e"
WSIZE="5G"

function test_write_cahce()
{
    testbs=$1; dirname=$2; testdir="/mnt/orcafs/${dirname}"
    logfile="${LOGPATH}/${dirname}_${testbs}_write_cache.log"
    rm -f ${testdir}/*; sleep 10; date
    cmd="mpirun ${MPI_PARAM} -wd ${testdir} ior ${IOR_PARAM} -b ${WSIZE} -F -t ${testbs} -w -k"
    eval ${cmd} &> ${logfile}
}

function test_write_direct()
{
    testbs=$1; dirname=$2; testdir="/mnt/orcafs/${dirname}"
    logfile="${LOGPATH}/${dirname}_${testbs}_write_direct.log"
    rm -f ${testdir}/*; sleep 10; date
    cmd="mpirun ${MPI_PARAM} -wd ${testdir} ior ${IOR_PARAM} -b ${WSIZE} -F -t ${testbs} -w -k --posix.odirect"
    eval ${cmd} &> ${logfile}
}

function test_randwrite_cahce()
{
    testbs=$1; dirname=$2; testdir="/mnt/orcafs/${dirname}"
    logfile="${LOGPATH}/${dirname}_${testbs}_randwrite_cache.log"
    rm -f ${testdir}/*; sleep 10; date
    cmd="mpirun ${MPI_PARAM} -wd ${testdir} ior ${IOR_PARAM} -b ${WSIZE} -F -t ${testbs} -w -k -z"
    eval ${cmd} &> ${logfile}
}

function test_randwrite_direct()
{
    testbs=$1; dirname=$2; testdir="/mnt/orcafs/${dirname}"
    logfile="${LOGPATH}/${dirname}_${testbs}_randwrite_direct.log"
    rm -f ${testdir}/*; sleep 10; date
    cmd="mpirun ${MPI_PARAM} -wd ${testdir} ior ${IOR_PARAM} -b ${WSIZE} -F -t ${testbs} -w -k --posix.odirect -z"
    eval ${cmd} &> ${logfile}
}

#设置chunksize
set_chunksize()
{
  bs=$1; dirname=$2; testdir="/mnt/orcafs/${dirname}"
  if [ $bs == "4k" ]; then chunksize="512k"; else chunksize="1024k"; fi
  
  echo "--- setpattern as $chunksize ---"
  orcafs-ctl --setpattern --chunksize=$chunksize $testdir --storagepoolid=2
}

function test_all()
{
    test_bs=$1
    test_dirname=$2
    testdir="/mnt/orcafs/${test_dirname}"; rm -f ${testdir}/*
    set_chunksize ${test_bs} ${test_dirname}

    test_write_direct ${test_bs} ${test_dirname}
    test_write_cahce ${test_bs} ${test_dirname}
    
    test_randwrite_direct ${test_bs} ${test_dirname}
    test_randwrite_cahce ${test_bs} ${test_dirname}
}

BS="1024k"; DIR=${NORMALDIR}; test_all ${BS} ${DIR}
BS="4k";    DIR=${NORMALDIR}; test_all ${BS} ${DIR}

BS="1024k"; DIR=${QUOTADIR}; test_all ${BS} ${DIR}
BS="4k"; WSIZE="500M"; DIRNAME=${QUOTADIR}; test_all ${BS} ${DIRNAME}

#查看结果
#IOPS       `grep -A1 -E '++ mpirun| Mean\(OPs\)' normaldir_4k_*`
#BW          `grep  -E '++ mpirun|Max Write' normaldir_1024k_*`
#IOPS       `grep -A1 -E '++ mpirun| Mean\(OPs\)' quotadir_4k_*`
#BW          `grep  -E '++ mpirun|Max Write' quotadir_1024k_*`